import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/LoginView.vue'
import storeManage from "../views/storeManage/storeManageView.vue"
import addStore from "../views/storeManage/addStoreView.vue"
import shopCategory from "../views/storeManage/shopCategoryView.vue"
import shopOrder from "../views/storeManage/shopOrderView.vue"
import shopDetail from "../views/storeManage/shopDetailView.vue"

const routes = [
  {
    path: '/',
    redirect: '/Login'
  },
  {
    path: '/Login',
    name: "Login",
    component: Login
  },
 
  {
    path: '/home',
    name: "home",
    // meta: { requiresAuth: true },
    component: () => import("../views/HomeView.vue"),
    children: [
      /**
       * 首页下的菜单子页面，将自己的静态路由放入对应位置
       * 每个模块的最后一个路由后记得加个逗号(,)防止报错
      */

      // 系统首页

      {//预约记录
        path: "/AboutView",
        name: "AboutView",
        component: () => import("../views/AboutView.vue"),
      },

      {//预约记录
        path: "/CoachCheckinView",
        name: "CoachCheckinView",
        component: () => import("../views/CoachCheckinView.vue"),
      },

      // 用户管理
      {// 会员列表
        path: "/MembershipList",
        name: "MembershipList",
        component: () => import("../views/UserManagement/MembershipList.vue"),
      },
      {//会员详情
        path: "/MembershipDetails",
        name: "MembershipDetails",
        component: () => import("../views/UserManagement/MembershipDetails.vue"),
      },
      {// 编辑个人信息 editInformation
        path: "/editInformation",
        name: "editInformation",
        component: () => import("../views/UserManagement/editInformation.vue"),
      },
      {//会员等级 GradeOfMembership
        path: "/GradeOfMembership",
        name: "GradeOfMembership",
        component: () => import("../views/UserManagement/GradeOfMembership.vue"),
      },
      {// 会员卡 membershipCard
        path: "/membershipCard",
        name: "membershipCard",
        component: () => import("../views/UserManagement/membershipCard.vue"),
      },
      {// 设置会员卡 setVipCard
        path: "/setVipCard",
        name: "setVipCard",
        component: () => import("../views/UserManagement/setVipCard.vue"),
        props: route => ({ query: route.query.id }),
      },
      {// 会员卡信息 vipCardManagement
        path: "/vipCardManagement",
        name: "vipCardManagement",
        component: () => import("../views/UserManagement/vipCardManagement.vue"),
      },
      {// 会员卡编辑 setVipCardManagement
        path: "/setVipCardManagement",
        name: "setVipCardManagement",
        component: () => import("../views/UserManagement/setVipCardManagement.vue"),
      },
      {// 教练列表 CoachList
        path: "/CoachList",
        name: "CoachList",
        component: () => import("../views/UserManagement/CoachList.vue"),
      },
      {// 编辑教练 CoachEditor
        path: "/CoachEditor",
        name: "CoachEditor",
        component: () => import("../views/UserManagement/CoachEditor.vue"),
      },
      {// 编辑教练  checkCoach
        path: "/checkCoach",
        name: "checkCoach",
        component: () => import("../views/UserManagement/checkCoach.vue"),
      },
      // 商城管理
      {
        path: "/storeManage",
        name: "storeManage",
        component: () => import("../views/storeManage/storeManageView.vue"),
      },
      //添加编辑
      {
        path: '/addStore',
        name: "addStore",
        component: () => import("../views/storeManage/addStoreView.vue"),
      },
      {
        path: '/shopCategory',
        name: "shopCategory",
        component: shopCategory
      },
      {
        path: '/shopOrder',
        name: "shopOrder",
        component: shopOrder
      },
      {
        path: '/shopDetail',
        name: "shopDetail",
        component: shopDetail
      },
      // 课程管理
      // {团课管理}
      {
        path: "/GroupScheduleView",
        name: "GroupScheduleView",
        component: () => import("../views/GroupScheduleView.vue"),
      },

      {
        path: "/MembershipCardView",
        name: "MembershipCardView",
        component: () => import("../views/MembershipCardView.vue"),
      },
      {
        path: "/EditorialGroupView",
        name: "EditorialGroupView",
        component: () => import("../views/EditorialGroupView.vue"),
      },
      {
        path: "/NewGroupCoursesView",
        name: "NewGroupCoursesView",
        component: () => import("../views/NewGroupCoursesView.vue"),
      },
      {
        path: "/AppointmentView",
        name: "AppointmentView",
        component: () => import("../views/AppointmentView.vue"),
      },
      {
        path: "/LeagueClassView",
        name: "LeagueClassView",
        component: () => import("../views/LeagueClassView.vue"),
        // redirect: '/calendar',
      },
      //{私教管理}
      {
        path: "/PrivateEducationView",
        name: "PrivateEducationView",
        component: () => import("../views/PrivateEducationView.vue"),
      },
      {
        path: "/NewPrivateEducation",
        name: "NewPrivateEducation",
        component: () => import("../views/NewPrivateEducation.vue"),
      },

      {
        path: "/ScheduleView",
        name: "ScheduleView",
        component: () => import("../views/ScheduleView.vue"),
      },
      //{评价管理}
      {
        path: "/EvaluationView",
        name: "EvaluationView",
        component: () => import("../views/EvaluationView.vue"),
      },

      // 首页
      {
        path: "",
        redirect:"homepage"
        
      },
      {
        path: "/homepage",
        name: "homepage",
        component: () => import("../views/homepage.vue")
      },
      {
        path: "/zhanghuzl",
        name: "zhanghuzl",
        component: () => import("../views/zhanghuzl.vue")
      },
      // 场馆管理
      {
        path: "/Changguan",
        name: "Changguan",
        component: () => import("../views/Changguan.vue")
      },
      {
        path: "/Changguantj",
        name: "Changguantj",
        component: () => import("../views/Changguantj.vue")
      },
      // 系统管理
      //    成员管理
      {
        path: "member",
        name: "member",
        component: () => import("../views/zq/Member.vue")
      },
      //    添加/修改成员
      {
        path: "memberUpdate",
        name: "memberUpdate",
        component: () => import("../views/zq/MemberUpdate.vue")
      },
      //    角色管理
      {
        path: "role",
        name: "role",
        component: () => import("../views/zq/Role.vue")
      },
      //    广告管理
      {
        path: "advertising",
        name: "advertising",
        component: () => import("../views/zq/Advertising.vue")
      },
      //    广告添加/修改
      {
        path: "adverUpdate",
        name: "adverUpdate",
        component: () => import("../views/zq/AdverUpdate.vue")
      },
      //    公告管理
      {
        path: "notice",
        name: "notice",
        component: () => import("../views/zq/Notice.vue")
      },
      //    系统配置
      {
        path: "setting",
        name: "setting",
        component: () => import("../views/zq/SystemSetting.vue")
      },

    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
});
// 全局守卫：登录拦截 本地没有存token,请重新登录
router.beforeEach((to, from, next) => {
  if (to.path === '/Login') {
    // 如果当前用户已经登录，则直接跳转至首页
    if (sessionStorage.getItem('token')) {
      next('/home');
    } else {
      next();
    }
  } else { // 不是登录页面
    // 如果用户还未登录，则跳转至登录页面
    if (!sessionStorage.getItem('token')) {
      next({ path: '/Login' });
    } else {
      next();
    }
  }
});


export default router
